<!-- 圆环进度 -->
<template>
  <div class="bar-progree-content">
    <div :class="['out-circle', borderColor]">
      <div :class="['inner-circle', innerCircleColor]">
        <base-echarts :options="barOptions" />
      </div>
    </div>
    <div class="title">{{title}}</div>
  </div>
</template>

<script>
import BaseEcharts from "./BaseEcharts.vue";
export default {
  name: "BarProgress",
  components: {
    BaseEcharts,
  },
  props: {
    // 外圈颜色
    borderColor: {
      type: String,
      default: "border-blue",
    },
    // 内圈颜色
    innerCircleColor: {
      type: String,
      default: "inner-blue",
    },
    // 进度数据
    progress: {
      type: [String, Number],
      default:0,
    },
    // 标题
    title: {
      type: String,
      default: "",
    },
  },
  computed: {
    mainColor() {
      return this.innerCircleColor === "inner-blue" ? "#7BBFF2" : "#4EE38C";
    },
    barOptions() {
      return {
        title: {
          text: this.progress + "%",
          textStyle: {
            color: this.mainColor,
            fontSize: 14,
          },
          top: "center",
          left: "center",
        },
        polar: [
          {
            radius: [],
            center: [],
          },
        ],
        angleAxis: {
          max: 100,
          show: false,
          inverse: false,
        },
        radiusAxis: {
          type: "category",
          show: true,
          axisLabel: {
            show: false,
          },
          axisLine: {
            show: false,
          },
          axisTick: {
            show: false,
          },
        },

        series: [
          //分割刻度
          {
            type: "gauge",
            radius: "100%",
            clockwise: false,
            startAngle: 90,
            endAngle: -269.99,
            splitNumber: 15,
            detail: {
              offsetCenter: [0, 0],
              formatter: " ",
            },
            pointer: {
              show: false,
            },
            axisLine: {
              show: true,
              lineStyle: {
                color: [
                  [this.progress / 100, "transparent"],
                  [1, this.mainColor],
                ],
                width: 6,
              },
            },
            axisTick: {
              show: false,
            },
            splitLine: {
              show: true,
              length: 6,
              distance: -6,
              lineStyle: {
                color: this.borderColor === "border-blue" ? "#0b1f33" : "#183634",
                width: 2,
              },
            },
            axisLabel: {
              show: false,
            },
          },
        ],
      };
    },
  },
};
</script>
<style scoped lang="scss">
.bar-progree-content {
  margin-right: 20px;
}
.out-circle {
  margin: 0 auto;
  padding: 8px;
  width: 87px;
  height: 87px;
  border: 2px solid;
  border-radius: 50%;
}
.border-green {
  border-color: #245c3b;
}
.border-blue {
  border-color: #174e77;
}
.inner-circle {
  width: 100%;
  height: 100%;
  border-radius: 50%;
}
.inner-blue {
  background: radial-gradient(circle at center, transparent 0, rgba(10, 52, 87, 0.5) 100%);
}
.inner-green {
  background: radial-gradient(circle at center, transparent 0, rgba(42, 114, 80, 0.5) 100%);
}
.title {
  display: inline-block;
  margin-top: 4px;
  text-align: center;
}
</style>
